package oriol.forns.gutierrez;



import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;

@SuppressLint("ParserError")
public class Base {

	Resources resources;
	BitmapFactory.Options options;
	public Objecte plataforma;
	private ArrayList<Bitmap> img;

	public Base(Resources rs) {
		img = new ArrayList<Bitmap>();
		float x;
		float y;
		float tx;
		float ty;
		tx = ((float)GV.Screen.metrics.widthPixels*0.25f);
		ty = ((float)GV.Screen.metrics.heightPixels*0.05f);
		x = ((float)GV.Screen.metrics.widthPixels/2) - (tx/2);
		y = (float)GV.Screen.metrics.heightPixels - 2*ty;
		options = new BitmapFactory.Options();
		options.inPreferredConfig = Bitmap.Config.ARGB_8888;
		resources = rs;
		
		Bitmap im = BitmapFactory.decodeResource(resources, R.drawable.platform, options);
		plataforma = new Objecte(x, y, 0, 0, tx, ty,  im);
		img.add(plataforma.img);
		img.add(Bitmap.createScaledBitmap(BitmapFactory.decodeResource(resources, R.drawable.plataforma, options),(int)tx,(int)ty,false));
	}
	
	
	public void mou(float nx) {
		plataforma.x += nx;
		if (plataforma.x > (float)GV.Screen.metrics.widthPixels-plataforma.tx) plataforma.x = (float)GV.Screen.metrics.widthPixels-plataforma.tx;
		else if (plataforma.x < 0) plataforma.x = 0;
	}
	
	public void nou(){
		plataforma.tx = ((float)GV.Screen.metrics.widthPixels*0.25f);
		plataforma.ty = ((float)GV.Screen.metrics.heightPixels*0.05f);
		plataforma.x = ((float)GV.Screen.metrics.widthPixels/2) - (plataforma.tx/2);
		plataforma.y = (float)GV.Screen.metrics.heightPixels - 2*plataforma.ty;
		plataforma.reescala();
	}
	
	public void draw(Canvas canvas) {
		plataforma.draw(canvas);
	}

	public void tam(boolean creix) {
		if (creix) {
			plataforma.tx += (float)GV.Screen.metrics.widthPixels*0.05f;
			if (plataforma.tx > (float)GV.Screen.metrics.widthPixels*0.4f) plataforma.tx = (float)GV.Screen.metrics.widthPixels*0.4f;
		}
		else {
			plataforma.tx -= (float)GV.Screen.metrics.widthPixels*0.05f;
			if (plataforma.tx < (float)GV.Screen.metrics.widthPixels*0.1f) plataforma.tx = (float)GV.Screen.metrics.widthPixels*0.1f;
		}
		plataforma.reescala();
	}

	public void shoot(boolean dispara) {
		if (dispara){
			GV.Instancies.trets = 20;
			plataforma.img = img.get(1);
		}
		else {
			GV.Instancies.trets = -1;
			plataforma.img = img.get(0);
		}
		plataforma.reescala();
	}

}
